<!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
      <title>title</title>
      <link rel="stylesheet" type="text/css" href="../css/api.css"/>
      <style>
          body{

          }
          .btn {
              width: auto;
              height: 50px;
              margin-left: 32px;
              margin-right: 32px;
              margin-top: 32px;
              background-color: #e3007f;
              line-height: 50px;
              color: #fff;
              font-size: 24px;
              text-align: center;
              border-radius: 8px;
          }
          .highlight {
              opacity: 0.7;
          }
      </style>
  </head>
  <body>
    <div class="btn" tapmode="highlight" onclick="fnTest();">测试</div>
    <div class="btn" tapmode="highlight" onclick="setSign();">获取Sign</div>
    <div class="btn" tapmode="highlight" onclick="fnDecrypt();">aes解密</div>
  </body>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/cryptojs/components/core-min.js"></script>
  <script type="text/javascript" src="../script/cryptojs/rollups/aes.js"></script>
  <script type="text/javascript" src="../script/crypto-helper.js"></script>
  <script type="text/javascript">
      apiready = function(){
        did = api.deviceId;
      };

      var did; //设备号
      function fnTest() {
        var signStr = setSign();
        api.ajax({
          url: 'https://api.mingzhuyuyan.com/api/test',
          method: 'GET',
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            "did": did,
            "version": "1",
            "apptype": "android",
            "sign": signStr,
          },
          data: {
            values: {

            }
          }
        },
        function(ret, err) {
          if(ret){
            alert(JSON.stringify(ret));
          }else{
            alert('请求失败');
          }
        });
      }

      function setSign() {
        var arr = new Array();
        var timestamp = (new Date()).valueOf();
        arr['did'] = did;
        arr['version'] = 1;
        arr['time'] = timestamp;

        var str='';
        str = 'did='+arr['did']+'&time='+arr['time']+'&version='+arr['version'];
        console.log(str);
        // for (key in arr) {
        //   val = arr[key];
        // }
        // var enStr = encrypt(str);
        // console.log(enStr);
        return encrypt(str);
      }

      function fnDecrypt() {
        var enStr = '';
        var deStr = decrypt(enStr);
        console.log(deStr);
      }

  </script>
  </html>
